from langchain_community.chat_models import ChatTongyi
from langchain.prompts import ChatPromptTemplate
import os

os.environ["DASHSCOPE_API_KEY"] = "sk-9d8f1914800e497f8717144e860f99bc"
llm = ChatTongyi()

template = ChatPromptTemplate.from_messages([
    ("system", "你是一个优秀的助手. 你的名字是 {name}."),
    ("human", "你好，你最近过的好嘛?"),
    ("ai", "最近过的不错"),
    ("human", "{user_input}"),
])

messages = template.format_messages(
    name="小郎同学",
    user_input="你的名字是什么"
)
res=llm.invoke(messages)
print(res)
